package com.ruoyi.activity.api.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.ruoyi.activity.domain.TbUser;
import com.ruoyi.activity.domain.TbUserCoupon;
import com.ruoyi.activity.service.ITbUserCouponService;
import com.ruoyi.activity.service.ITbUserService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author jll
 * @createTime 2025/6/14
 * @description api用户控制层
 * @version: 1.0
 */
@RestController
@RequestMapping("/api/user")
@Api("用户模块API")
public class UserController {

    @Autowired
    private ITbUserService userService;

    @Autowired
    private ITbUserCouponService userCouponService;

    @GetMapping("/info")
    @ApiOperation("获取用户信息")
    public AjaxResult info() {
        // 1. 获取当前登录用户的 ID
        long userId = StpUtil.getLoginIdAsLong();

        // 2. 根据用户 ID 查询用户信息
        TbUser user = userService.selectTbUserById(userId);

        TbUserCoupon tbUserCoupon = userCouponService.selectTbUserCouponByUserId(userId);

        Map<String, Object> data = new HashMap<>();
        data.put("user", user);
        data.put("coupon", tbUserCoupon);

        // 3. 返回用户信息
        return AjaxResult.success(data);
    }
}
